package com.whfc.ms.api.quality.service.impl;

import com.whfc.common.result.PageData;
import com.whfc.ms.api.quality.service.MsQualityTaskService;
import com.whfc.quality.dto.*;
import com.whfc.quality.param.*;
import com.whfc.quality.service.QualityTaskService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @ClasssName MsQualityTaskServiceImpl
 * @Description 检查任务
 * @Author hw
 * @Date 2021/3/10 15:00
 * @Version 1.0
 */
@Service
public class MsQualityTaskServiceImpl implements MsQualityTaskService {

    @DubboReference(interfaceClass = QualityTaskService.class, version = "1.0.0")
    private QualityTaskService qualityTaskService;

    @Override
    public void taskAdd(QualityTaskAddParam param) {
        qualityTaskService.taskAdd(param);
    }

    @Override
    public void taskEdit(QualityTaskEditParam param) {
        qualityTaskService.taskEdit(param);
    }

    @Override
    public void del(Integer taskId) {
        qualityTaskService.delTask(taskId);
    }

    @Override
    public PageData<QualityTaskDTO> list(Integer deptId, String title, Integer overdue, Date startTime, Date endTime, Integer state, Integer pageSize, Integer pageNum) {
        return qualityTaskService.taskList(deptId, title, overdue, state, startTime, endTime, pageNum, pageSize);
    }

    @Override
    public QualityExecNumDTO taskNum(Integer deptId, String title, Integer overdue, Date startTime, Date endTime) {
        return qualityTaskService.taskNum(deptId, title, overdue, startTime, endTime);
    }

    @Override
    public PageData<QualityTaskDetailsDTO> taskDetails(Integer taskId, Integer pageSize, Integer pageNum) {
        return qualityTaskService.taskDetails(taskId, pageNum, pageSize);
    }

    @Override
    public List<QualityTaskDetailsDTO> taskDetails(Integer taskId) {
        return qualityTaskService.taskDetails(taskId);
    }

    @Override
    public PageData<QualityExecDetailsDTO> execDetailsList(Integer taskItemId, Integer pageSize, Integer pageNum) {
        return qualityTaskService.execDetailsList(taskItemId, pageNum, pageSize);
    }

    @Override
    public QualityExecNumDTO execNum(Integer taskItemId) {
        return qualityTaskService.execNum(taskItemId);
    }

    @Override
    public PageData<QualityTaskExecDTO> taskExecList(Integer userId, Integer deptId, String keyword, Integer overdue, Integer state, Date startTime, Date endTime, Integer pageSize, Integer pageNum) {
        return qualityTaskService.taskExecList(userId, deptId, keyword, overdue, null, state, startTime, endTime, pageNum, pageSize);
    }

    @Override
    public QualityExecNumDTO execNum(Integer userId, Integer deptId, String keyword, Integer overdue, Date startTime, Date endTime) {
        return qualityTaskService.execNum(userId, deptId, keyword, overdue, startTime, endTime);
    }

    @Override
    public void execAdd(QualityTaskReportParam param) {
        qualityTaskService.report(param);
    }

    @Override
    public void execDel(Integer execId) {
        qualityTaskService.execDel(execId);
    }

    @Override
    public void execComplete(QuailTaskCompleteParam param) {
        qualityTaskService.complete(param);
    }

    @Override
    public void taskRelease(QualityTaskReleaseParam param) {
        qualityTaskService.taskRelease(param);
    }

    @Override
    public QualityExecNumDTO execNum(Integer userId, Integer deptId, Integer partId, Date startTime, Date endTime) {
        return qualityTaskService.execNum(userId, deptId, partId, startTime, endTime);
    }

    @Override
    public List<QualityTaskExecDTO> execList(Integer userId, Integer deptId, Integer partId, Integer report, Date startTime, Date endTime) {
        if (1 == report) {
            return qualityTaskService.taskExecList(userId, deptId, partId, startTime, endTime);
        } else {
            return qualityTaskService.taskExecList(deptId, partId, startTime, endTime);
        }
    }

    @Override
    public PageData<QualityTaskExecDTO> execList(Integer userId, Integer deptId, Integer partId, Integer report, Date startTime, Date endTime, Integer pageSize, Integer pageNum) {
        if (1 == report) {

            return qualityTaskService.taskExecList(userId, deptId, partId, startTime, endTime, pageNum, pageSize);
        } else {
            return qualityTaskService.taskExecList(deptId, partId, startTime, endTime, pageNum, pageSize);
        }
    }

    @Override
    public QualityExecNumDTO execNumDeptId(Integer deptId, String title, Integer overdue, Date startTime, Date endTime) {
        return qualityTaskService.execNum(null, deptId, title, overdue, startTime, endTime);
    }

    @Override
    public void execExport(String execIds, Integer deptId) {
        String[] strIds = execIds.split(",");
        List<Integer> intIds = Arrays.stream(strIds).map(Integer::valueOf).collect(Collectors.toList());
        qualityTaskService.excExport(intIds, deptId);
    }
}
